package view;

import Utils.DBUtils;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

public class ConnFra extends JFrame{
    private JButton connBtn;
    private javax.swing.JPanel JPanel;
    private JComboBox DBSComboBox;

    private String DBSName;

    public DBUtils dbUtil=new DBUtils();

    public Connection conn;

    public ConnFra(){
        setContentPane(JPanel);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setVisible(true);
        setBounds(200,200,500,300);
        DBSComboBox.addItem("chengdu");
        //响应
        addActionLsner();
    }

    private void addActionLsner() {
        //连接
        connBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                DBSName=(String) DBSComboBox.getSelectedItem();
                try {
                    conn=dbUtil.getConnection(DBSName);
                    new mainFra(conn);
                    dispose();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null,"连接失败");
                    throw new RuntimeException(ex);
                }
            }
        });
    }
}
